<?php
/**
 * Author: 式神(vashi)
 * email: 289650682@qq.com
 * Date: 2019/2/21 16:40
 * FileName: PositionList.php
 */

namespace app\cms\controller;

use app\common\controller\Common;

class PositionList extends Common
{
    protected $middleware = ['Auth'];

    protected function initialize()
    {
        parent::initialize();
        $this->db = new \app\cms\model\PostArticle();
    }
    public function index(){
        $input=input('get.');
        $input['rows'] = isset($input['rows']) ? $input['rows'] : config('rows');
        $input['page'] = isset($input['page']) ? $input['page'] : 1;

        $map = $this->getMap($input);
        $order = $this->getOrder($input);
        $res['total'] = $this->db->where($map)->where('post_id',$input['id'])->order($order)->count();
        $data = $this->db->where($map)->where('post_id',$input['id'])->order($order)->limit($input['rows'])->page($input['page'])->select();
		foreach($data as $v){
			$article = (new \app\cms\model\Article())->find($v['article_id']);
			$v['title']=$article['title'];
			$v['create_time']=$article['create_time'];
		}
        $res['rows'] =$data;
        $res['page'] =$input['page'];
        $d=[
            "code"=>0,
        ];
        $d['data']=$res;
        return json($d);
    }
    public function getone(){
        $get = input('get.');
        $d=[
            "code"=>0,
        ];
        $res = \app\cms\model\Position::find($get['id']);
        $d['data']=$res;
        return json($d);
    }
    //添加
    public function add(){
        $post=input('post.');
        $res=$this->db->add($post);
        return json($res);
    }
    //编辑
    public function edit(){
        $res=$this->db->editSort(input('post.'));
        return json($res);
    }
    //删除
    public function del(){
        $post=input('post.');
        $res=$this->db->del($post);
        $res['msg'] = str_replace("删除","移除",$res['msg']);
        return json($res);
    }

}